
#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include "MySocket.h"
#include <stdio.h>
#include "message.h"
#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT "27015"

int __cdecl main(void) 
{
    
    int iResult;

	printf("%d ", sizeof(MESSAGE));
	printf("%d ", sizeof(M_ANSWERANDMARK));
	printf("%d ", sizeof(M_CHOICE));
	printf("%d ", sizeof(M_FINALMARK));
	printf("%d ", sizeof(M_NEWMEM));
	printf("%d ", sizeof(M_QUESTION));
	printf("%d ", sizeof(M_QUIT));
	printf("%d ", sizeof(M_REGISTER));
	printf("%d ", sizeof(M_REGISTERRESULT));
	printf("%d ", sizeof(M_START));

    char recvbuf[DEFAULT_BUFLEN];
    int recvbuflen = DEFAULT_BUFLEN;
    
	if (!WndSocketStartup()) {
		printf("start up window socket fail\n");
		return 1;
	}

	CListenSocket listenSocket;
	CConnectSocket connectSocket;

	listenSocket.Create(DEFAULT_PORT);
	listenSocket.Listen();
	printf("server is waiting for a connection\n");
	listenSocket.Accept(connectSocket);
	

   
    while(true) {
		PMESSAGE pMsg = new MESSAGE;
		iResult = connectSocket.Receive((void*) pMsg, MSGSIZE);
		
		if (pMsg->opcode == MSG_CHOICE) {
			PM_CHOICE pMsgChoice = (PM_CHOICE) pMsg;
			printf("> Msg: %d\n", pMsgChoice->choice);
		}
		
    
    } 
	

    WndSocketCleanup();
    return 0;
}